package com.springboot.util;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @author zhenwei.wang 2019/1/10
 */
public class EncryptUtils {

    private static final int DEFAULT_KEY = 7;

    /**
     * 加密，通过位运算进行简单加密
     * @param str
     * @return
     */
    public static String encrypt(String str) {
        return encrypt(str, DEFAULT_KEY);
    }

    public static String encrypt(String str, int key) {
        char[] chars = str.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            chars[i] = (char) (chars[i] ^ key);
        }
        return new String(chars);
    }

    public static Map<String,String> encrypt(String ... str) {
        Map<String, String> map = new LinkedHashMap<>();
        for (String s : str) {
            map.put(s, encrypt(s));
        }
        return map;
    }

        /**
         * 解密，通过位运算还原字符串
         * @param string
         * @return
         */
    public static String decrypt(String string) {
        return encrypt(string);
    }

    /*public static void main(String[] args) {
        Map<String, String> encrypt = encrypt("2013001", "08Oe4YI71I5S3e72qYT2","8801111111377","5688130133018597");
        System.out.println(encrypt);
        String encrypt1 = encrypt("5688130133018597");
        String decrypt = decrypt(encrypt1);
    }*/

    public static void main(String[] args) {
        String s = encrypt("e0aa7b0cbfffac8589b50be58f56cf73");
        String decrypt = decrypt("b7ff0e7deaaafd?2?>e27eb2?a21da04");
    }
}
